from datetime import date
from typing import Optional, List
from pydantic import BaseModel

##医生排班表增删改查
class ScheduleCreate(BaseModel):
    doctor_id: int
    schedule_date: date
    department: str
    am_remaining: int = 0
    pm_remaining: int = 0

    def check(self):
        if self.doctor_id <= 0:
            raise ValueError("Doctor ID must be positive")
        if not 0 < len(self.department) < 50:
            raise ValueError("Department must be between 0 and 30 characters")
        if self.am_remaining < 0 or self.pm_remaining < 0:
            raise ValueError("Remaining slots cannot be negative")

class ScheduleUpdate(BaseModel):
    schedule_date: Optional[date] = None
    department: Optional[str] = None
    am_remaining: Optional[int] = None
    pm_remaining: Optional[int] = None

    def check(self):
        if self.department is not None and not 0 < len(self.department) < 50:
            raise ValueError("Department must be between 0 and 30 characters")
        if self.am_remaining is not None and self.am_remaining < 0:
            raise ValueError("AM remaining slots cannot be negative")
        if self.pm_remaining is not None and self.pm_remaining < 0:
            raise ValueError("PM remaining slots cannot be negative")



class ScheduleQuery(BaseModel):
    schedule_date: date
    time_period: str  # 'AM' or 'PM'
    department: str



class DoctorScheduleResponse(BaseModel):
    schedule_id:int     #添加返回排班记录id
    doctor_info: dict
    am_remaining: int
    pm_remaining: int

class DoctorScheduleListResponse(BaseModel):
    is_empty: bool
    results: List[DoctorScheduleResponse] = []